package com.xquant.trade.utils;

import java.text.MessageFormat;

/**
 * @author B946
 * @date 2021/4/7 10:09
 * @description:
 */
public class CdsFpmlUtil {

    public static final String baseFpml_1 = "<?xml version=\"1.0\"?>\n" +
            "<FpML version=\"4-2\" xmlns=\"http://www.fpml.org/2005/FpML-4-2\" xmlns:xq=\"http://www.xquant.com/2007/xQFpML-1-0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.xquant.com/2007/xQFpML-1-0 ../schemaext/xqfpml-main-1-0.xsd http://www.fpml.org/2005/FpML-4-2 ../schema/fpml-main-4-2.xsd\" xsi:type=\"DataDocument\">\n" +
            "  <validation/>\n" +
            "  <trade>\n" +
            "    <tradeHeader>\n" +
            "      <partyTradeIdentifier>\n" +
            "        <partyReference href=\"Party\"/>\n" +
            "        <tradeId tradeIdScheme=\"http://www.xquant.com/fpml/tradeid\"/>\n" +
            "      </partyTradeIdentifier>\n" +
            "      <partyTradeIdentifier>\n" +
            "        <partyReference href=\"Counterparty\"/>\n" +
            "        <tradeId tradeIdScheme=\"http://www.xquant.com/fpml/tradeid\"/>\n" +
            "      </partyTradeIdentifier>\n" +
            "      <tradeDate id=\"tradeDate\">2016-09-30</tradeDate>\n" +
            "    </tradeHeader>\n" +
            "    <creditDefaultSwap>\n" +
            "      <productType productTypeScheme=\"http://www.xquant.com/fpml/producttype\"/>\n";

    private static String baseFpml_underly_2 =  "      <productId productIdScheme=\"http://www.xquant.com/fpml/instrumentid\">{0},SWP_CD,X_CNBD</productId>\n";

    public static final String baseFpml_3 =  "      <generalTerms id=\"generalTerms_creditDefaultSwap\">\n" +
            "        <effectiveDate id=\"effectiveDate_creditDefaultSwap\">\n" +
            "          <unadjustedDate>2017-09-10</unadjustedDate>\n" +
            "          <dateAdjustments>\n" +
            "            <businessDayConvention>NONE</businessDayConvention>\n" +
            "            <businessCentersReference href=\"primaryBizCenter_creditDefaultSwap\"/>\n" +
            "          </dateAdjustments>\n" +
            "        </effectiveDate>\n" +
            "        <scheduledTerminationDate id=\"scheduledTerminationDate_creditDefaultSwap\">\n" +
            "          <unadjustedDate>2018-09-20</unadjustedDate>\n" +
            "          <dateAdjustments>\n" +
            "            <businessDayConvention>NONE</businessDayConvention>\n" +
            "            <businessCentersReference href=\"primaryBizCenter_creditDefaultSwap\"/>\n" +
            "          </dateAdjustments>\n" +
            "        </scheduledTerminationDate>\n" +
            "        <dateAdjustments>\n" +
            "          <businessDayConvention>FOLLOWING</businessDayConvention>\n" +
            "          <businessCenters id=\"primaryBizCenter_creditDefaultSwap\">\n" +
            "            <businessCenter businessCenterScheme=\"http://www.xquant.com/fpml/calendarname\">CHINA_IB</businessCenter>\n" +
            "          </businessCenters>\n" +
            "        </dateAdjustments>\n" +
            "        <buyerPartyReference href=\"Party\"/>\n" +
            "        <sellerPartyReference href=\"Counterparty\"/>\n" +
            "        <referenceInformation>\n" +
            "          <referenceEntity>\n";

    private static String baseFpml_entity_4 = "            <entityId entityIdScheme=\"http://www.xquant.com/fpml/entityid\">{0}</entityId>\n";

    public static final String baseFpml_5 = "          </referenceEntity>\n" +
            "          <unknownReferenceObligation/>\n" +
            "          <referencePrice>1</referencePrice>\n" +
            "        </referenceInformation>\n" +
            "      </generalTerms>\n" +
            "      <feeLeg id=\"Leg01\">\n" +
            "        <periodicPayment id=\"periodicPayment_creditDefaultSwap\">\n" +
            "          <paymentFrequency>\n" +
            "            <periodMultiplier>3</periodMultiplier>\n" +
            "            <period>M</period>\n" +
            "          </paymentFrequency>\n" +
            "          <calculationPeriodDatesAdjustments id=\"calculationPeriodDatesAdjustments_creditDefaultSwap\">\n" +
            "            <businessDayConvention>MODFOLLOWING</businessDayConvention>\n" +
            "            <businessCenters>\n" +
            "              <businessCenter businessCenterScheme=\"http://www.xquant.com/fpml/calendarname\">CHINA_IB</businessCenter>\n" +
            "            </businessCenters>\n" +
            "          </calculationPeriodDatesAdjustments>\n" +
            "          <fixedAmountCalculation>\n" +
            "            <fixedRate>0.01</fixedRate>\n" +
            "            <dayCountFraction dayCountFractionScheme=\"http://www.xquant.com/fpml/daycountername\">Actual/365 (Fixed)</dayCountFraction>\n" +
            "            <calculationAmount>\n" +
            "              <currency currencyScheme=\"http://www.fpml.org/ext/iso4217-2001-08-15\">CNY</currency>\n" +
            "              <amount>1</amount>\n" +
            "            </calculationAmount>\n" +
            "          </fixedAmountCalculation>\n" +
            "        </periodicPayment>\n" +
            "      </feeLeg>\n" +
            "      <protectionTerms id=\"Leg02\">\n" +
            "        <calculationAmount>\n" +
            "          <currency currencyScheme=\"http://www.fpml.org/ext/iso4217-2001-08-15\">CNY</currency>\n" +
            "          <amount>1</amount>\n" +
            "        </calculationAmount>\n" +
            "      </protectionTerms>\n" +
            "      <physicalSettlementTerms id=\"physicalSettlementTerms_creditDefaultSwap\">\n" +
            "        <settlementCurrency currencyScheme=\"http://www.fpml.org/ext/iso4217-2001-08-15\">CNY</settlementCurrency>\n" +
            "      </physicalSettlementTerms>\n" +
            "    </creditDefaultSwap>\n" +
            "  </trade>\n" +
            "  <party id=\"Party\">\n" +
            "    <partyId>Party</partyId>\n" +
            "  </party>\n" +
            "  <party id=\"Counterparty\">\n" +
            "    <partyId>Counterparty</partyId>\n" +
            "  </party>\n" +
            "</FpML>\n";

    public static String buildCdsUnderly4Fpml(String iCode){
        return MessageFormat.format(baseFpml_underly_2, iCode);
    }
    public static String buildCdsEntity4Fpml(String entityId){
        return MessageFormat.format(baseFpml_entity_4, entityId);
    }



}
